package biz.noip.strategy.players.view;

import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.TextOptions;
import org.andengine.util.modifier.IModifier;
import org.andengine.util.modifier.ease.EaseSineIn;

import android.opengl.GLES20;
import biz.noip.strategy.mediator.MediatorGame;
import biz.noip.strategy.players.Player;
import biz.noip.strategy.scenes.GameScene;
import biz.noip.strategy.scenes.InterfaceScene;
import biz.noip.strategy.util.ZIndex;

public class InfoCenterView {

	private InterfaceScene iScene;
	private GameScene gScene;
	private Sprite board;
	private boolean lock = false;

	public InfoCenterView(InterfaceScene iScene, GameScene gScene) {
		this.iScene = iScene;
		this.gScene = gScene;
		board = new Sprite(0, 350, 480, 128,
				this.gScene.textureMap.get("board"),
				this.gScene.vertexBufferObjectManager);
		board.setZIndex(ZIndex.INFO_PANEL_CENTER.ordinal());

	}

	public void showPanel(String message) {
		if (!lock) {
			final Text text = new Text(20, 370, gScene.font, message,
					new TextOptions(), gScene.vertexBufferObjectManager);
			text.setBlendFunction(GLES20.GL_SRC_ALPHA,
					GLES20.GL_ONE_MINUS_SRC_ALPHA);
			text.setZIndex(ZIndex.TEXT_PANEL_CENTER.ordinal());
			iScene.attachChild(board);
			iScene.attachChild(text);
			text.registerEntityModifier(new MoveModifier(5f, 20 + 100,
					20 + 100 + 0.4f, 370 + 20, 370 + 20 + 0.4f,
					new IEntityModifierListener() {

						public void onModifierStarted(IModifier<IEntity> arg0,
								IEntity arg1) {
							lock = true;
							for (Player player : gScene.getListPlayers()) {
								player.setSelectLock();
							}
						}

						public void onModifierFinished(IModifier<IEntity> arg0,
								IEntity arg1) {
							MediatorGame.getInstance()
									.deleteChild(text, iScene);
							MediatorGame.getInstance().deleteChild(board,
									iScene);
							for (Player player : gScene.getListPlayers()) {
								player.setSelectUnlock();
							}
							lock = false;
						}
					}, EaseSineIn.getInstance()));
		}
	}
}
